package com.zdb.controller;

import com.zdb.common.Result;
import com.zdb.pojo.Article;
import com.zdb.pojo.dto.ArticleDto;
import com.zdb.pojo.dto.ArticleSearchDto;
import com.zdb.service.ArticlesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/articles")
@RestController
public class ArticlesController {
    private static final Logger log = LoggerFactory.getLogger(ArticlesController.class);
    @Autowired
    private ArticlesService articlesService;


//    @GetMapping("/like-info")
//    public Result getLikeInfo(List<Integer> articleIds) {
//        return Result.sucess("获取点赞信息",articlesService.getLikeInfo(userId,articleId));
//    }

    @GetMapping("/{id}")
    public Result getArticle(@PathVariable("id") int id) {
        return Result.sucess("获取文章",articlesService.getArticle(id));
    }
    @GetMapping()
    public Result getArticles(ArticleSearchDto articleSearchDto) {
        log.info("进入文章列表控制器:{}", articleSearchDto);
        return Result.sucess("获取文章",articlesService.getArticles(articleSearchDto));
    }



    @DeleteMapping("/{id}")
    public Result deleteArticle(@PathVariable("id") int id) {
        return Result.sucess("删除文章",articlesService.deleteArticle(id));
    }
    @PostMapping()
    public Result addArticle(@RequestBody ArticleDto article) {
        return Result.sucess("添加文章",articlesService.addArticle(article));
    }
    @PutMapping("/")
    public Result updateArticle(@RequestBody ArticleDto article) {
        return Result.sucess("更新文章",articlesService.updateArticle(article));
    }
    @PostMapping("/{id}/view")
    public Result viewArticleIncrement(@PathVariable("id") Integer id) {
        articlesService.viewArticleIncrement(id);
        return Result.sucess("文章浏览数",null);
    }
    @PostMapping("/{id}/like")
    public Result likeArticle(@PathVariable("id") Integer id) {
        articlesService.likeArticleHandleder(id);
        return Result.sucess("文章点赞数",null);
    }
    @PostMapping("/{id}/collecting")
    public Result collectingArticle(@PathVariable("id") Integer id) {

        articlesService.collectingArticle(id);
        return Result.sucess("文章收藏数",null);
    }




}
